package com.domor.utils;

import com.domor.model.User;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class CommonUtils {

    /**
     * PagerHelper 分页传参，返回Page对象
     * @param params 查询参数
     * @return Page Page对象
     */
    public static Page startPage(Map<String, Object> params) {
        int pageNum = MapUtils.getIntValue(params, "page");
        int pageSize = MapUtils.getIntValue(params, "limit");
        return PageHelper.startPage(pageNum, pageSize);
    }

    public static User getSessionUser(HttpServletRequest req){
        return (User) req.getSession().getAttribute("user");
    }

    public static String getSessionUsername(HttpServletRequest req){
        return getSessionUser(req).getUsername();
    }

}
